package com.syh.feignapi.clients.fallback;

import com.syh.bscommon.pojo.Transactions;
import com.syh.feignapi.clients.CreditsClient;
import com.syh.feignapi.pojo.CarbonCredits;
import com.syh.feignapi.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.math.BigDecimal;

/**
 * @author syh 86187
 * @date 2024/7/25
 * com.syh.feignapi.clients.fallback
 * @description
 */
@Slf4j
public class CreditsClientFallback implements FallbackFactory<CreditsClient> {
    @Override
    public CreditsClient create(Throwable cause) {

        return new CreditsClient() {
            @Override
            public Result setinfo(CarbonCredits carbonCredits) {
                log.error("添加公司信息失败:{}",cause.getMessage());
                return Result.error("添加公司信息失败");
            }

            @Override
            public BigDecimal getCreditAmount(Integer companyId) {
                log.error("获取公司额度失败:{}",cause.getMessage());
                return new BigDecimal(0);
            }

            @Override
            public void updateCreditAmount(Integer companyId, BigDecimal emissionAmount) {
                throw new RuntimeException(cause.getMessage());
            }

            @Override
            public void updateCreditAmountAdd(Integer companyId, BigDecimal emissionAmount) {
                throw new RuntimeException(cause.getMessage());
            }

            @Override
            public Result getAccount(Integer companyId) {
                log.error("获取公司余额失败:{}",cause.getMessage());
                return Result.success(new BigDecimal(0));
            }

            @Override
            public void updateAccount_a(Transactions transactions) {
                throw new RuntimeException(cause.getMessage());
            }

            @Override
            public void updateAccount_s(Transactions transactions) {
                throw new RuntimeException(cause.getMessage());
            }

            @Override
            public void updateAccount_add_buy(Transactions transactions) {
                throw new RuntimeException(cause.getMessage());
            }

            @Override
            public void updateAccount_add_sell(Transactions transactions) {
                throw new RuntimeException(cause.getMessage());
            }
        };
    }
}
